<!--
  - Date: 2016年10月20日21:36:23
  - Description:
-->
<!DOCTYPE html>
<html lang="zh-Hans">
	<head>
		<title>修改密码</title>
	<meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chorme=1">
    <meta name="renderer" content="webkit">
    <script src="/static/cqzd/js/boot.js"></script>
		<style type="text/css">
			.mini-form-label{
				font-size: 20px;
				line-height: 50px;
				font-weight: normal;
				width: 130px;
			}
		</style>
</head>
<body>
<div style="padding-top:5px;">
	<form method="post" id = "form1" name="UpdateForm" action="">
		<table class="mini-form-table" style="width:100%;">
	      <tr>
	        <th class="mini-form-label"><label for="user.userId$text">当前用户：</label></th>
	        <td>
	          <input id="currentUser" class="mini-textbox mini-form-input" value="" enabled="false" />
	        </td>
	      </tr>
	      <tr class="odd">
	        <th class="mini-form-label"><label for="password$text">输入原密码：</label></th>
	        <td>
	          <input id="password" class="mini-password mini-form-input" name="oldPassword" required="true"/>
	        </td>
	      </tr>
	      <tr>
	        <th class="mini-form-label"><label for="pwd1$text">输入新密码：</label></th>
	        <td>
	          <input class="mini-password mini-form-input" id="pwd1" required="true" vtype="minLength:6"/>
	        </td>
	      </tr>
	      <tr class="odd">
	        <th class="mini-form-label"><label for="pwd2$text">确定新密码：</label></th>
	        <td>
	          <input class="mini-password mini-form-input" id="pwd2" name="password" required="true" onvalidation="onCheckEqual"/>
	        </td>
	      </tr>
	    </table>
		<div class="mini-btn-group bottom-btn-group">
			<a class="mini-button mini-btn mini-btn-ok" onclick="save">修改</a>
			<span class="mini-btn-separator"></span>
			<a class="mini-button mini-btn mini-btn-cancel" onclick="cancel">取消</a>
		</div>
	</form>
</div>

<script type="text/javascript">    
    mini.parse();

    var myInfo;

    HttpUtil.get('/security/sign/myInfo',function (e) {
		myInfo = e;
		mini.get('currentUser').setValue(myInfo.userId);
	});

    function save () {
    	var form = new mini.Form('#form1');
		form.validate();
		if (form.isValid() !== true) {
			return;
		}
    	var data  = form.getData(true,true);
		//提交修改，加密密码信息
		var param = {oldPassword:txkui.digest(data.oldPassword,myInfo.salt),password:txkui.digest(data.password,myInfo.salt)}
		HttpUtil.put('/security/sign/changePwAjax',param,function (e) {
			if(e.retCode == 1){
				alert("密码修改成功！");
				//要求重新登录
				top.location.href="/security/sign/out";
			}else{
				mini.alert("原密码填写错误！");
			}
		});
    }

    function cancel(){
      CloseWindow("cancel");
    }

  
    function onCheckEqual(e){
      if(e.isValid){
        var pwd = mini.get("pwd1").value;
        if(e.value!=pwd){
          e.errorText = "新密码不一致";
          e.isValid = false;
        }
      }
    }

    
    function CloseWindow(action){
      if(action=="close" && form.isChanged()){
        if(confirm("数据已改变,是否先保存?")){
          return false;
        }
      }else if(window.CloseOwnerWindow) 
        return window.CloseOwnerWindow(action);
      else
        return window.close();
    }
  </script>
</body>
</html>
